package com.yuyu.demo.demo_springboot.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yuyu.demo.demo_springboot.domain.Girl;
import com.yuyu.demo.demo_springboot.mapper.GirlMapper;

@Service
public class GirlService2 {
	@Autowired
	GirlMapper mapper;
	
	public Girl findById(Integer id){
		return mapper.selectByPrimaryKey(id);
	}
	
	public List<Girl> findAll(){
		return mapper.selectAll();
	}
	
	public long save(Girl entity){
		return mapper.insert(entity);
	}
	
	/**
	 * 测试事务
	 * @param entity
	 * @return
	 */
	@Transactional
	public long save2(){
		Girl g1 = new Girl();
		g1.setAge(11);
		g1.setName("11");
		g1.setCupSize("A");
		long r1 = mapper.insert(g1);
		
		Girl g2 = new Girl();
		g2.setAge(222);
		g2.setName("222");
		g2.setCupSize("BBBBBB");
		long r2 = mapper.insert(g2);
		return 2;
	}
	
	public long delete(Girl entity){
		return mapper.delete(entity);
	}
	
	public long list2(){
		return mapper.testS();
	}
	
}
